package com.leesche.zcsp.node.web.controller.web.user;

import com.leesche.zcsp.node.utils.web.messge.WebResult;
import com.leesche.zcsp.node.web.controller.template.UserTemplate;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.*;

/**
 * @author Jerry Chen
 * @version V1.0
 * @Title: RegisterController.java
 * @Description: TODO(用户注册控制器)
 * @date 2016年10月5日 下午10:05:14
 */
@Controller
@RequestMapping("/web/user")
public class SysUserController extends UserTemplate {

    private final static Logger LOGGER = Logger
            .getLogger(SysUserController.class.getName());

    private static final String CHANGEPASSWORD_VIEW = "web/userinfo/changepassword";
    private static final String CHANGETRANSFERPASSWORD_VIEW = "web/userinfo/changetransferpassword";


    @RequestMapping(value = "/showpassword", method = RequestMethod.GET)
    public String showChangePasswordView() {
        return CHANGEPASSWORD_VIEW;
    }

    @RequestMapping(value = "/showtransferpassword", method = RequestMethod.GET)
    public String showChangeTransferPasswordView() {
        return CHANGETRANSFERPASSWORD_VIEW;
    }


    @ResponseBody
    @RequestMapping(value = "/changePassword", method = RequestMethod.POST)
    public Map<String, Object> changeUserPassword(
            @RequestParam String oldPassword, @RequestParam String newPassword,
            HttpSession session) {
        try {

            return changeLoginPassword(oldPassword, newPassword);

        } catch (Exception e) {
            // TODO: handle exception
            LOGGER.error(e, e);
            return WebResult.failure(e).toMap();
        }
    }



    @ResponseBody
    @RequestMapping(value = "/changeTransferPassword", method = RequestMethod.POST)
    public Map<String, Object> changeUserTransferPassword(
            @RequestParam String oldPassword, @RequestParam String newPassword,
            HttpSession session) {
        try {
            return changeTransferPassword(oldPassword, newPassword);

        } catch (Exception e) {
            // TODO: handle exception
            LOGGER.error(e, e);
            return WebResult.failure(e).toMap();
        }
    }


}
